import axios from '../lib/http'
export default {
  songlist(_this) {
    _this.$axios
      .get("playlist/detail", {
        //通过url上面的id获取歌单详情信息
        params: {
          id: _this.$route.query.id,
        },
      })
      .then((res) => {
        // console.log(res.data.playlist);
        _this.userimg = res.data.playlist;
        _this.$store.commit("upmusiclist", res.data.playlist);
      });
  },
  // 获取单首歌曲的api
  ico() {
    axios.get('song/url', {
      params: {
        id: "1452654249"
      }
    }).then(res => {
      console.log(res.data.data);
    })
  },
   //获取所有歌曲
  details(id, state) {
    axios
    .get("song/detail?", {
      //获取歌曲
      params: {
        ids: id,
      },
    })
    .then((res) => {
      // console.log(state.musiclist.tracks[0]);
      res.data.songs.forEach((item, index) => {
        if (index < 9) {
          item.cdid = "0" + (index + 1)
        } else {
          item.cdid = (index + 1)
        }
        item.aix = "❤"
        item.playcond = index
      });
      state.sumlist = res.data.songs
    }).then(() => {
      //创建数据mp3id 里面有 歌曲id 图片 歌手 等等
      state.mp3id = []
      console.log(state.sumlist);
      state.sumlist.forEach(item => {
        let times = '0' + new Date(item.dt).getUTCMinutes() + ':' + new Date(item.dt).getSeconds()
        let mp3data = {
          id: item.id,
          cover: item.al.picUrl, //歌曲图片
          name: item.name, //歌名
          artist: item.ar[0].name, //歌手
          time: times //歌曲时间

        }
        state.mp3id.push(mp3data)
      })
    });

   
  },
  //切换音乐
  tabmusict(_this, row) {
    _this.$axios
      .get("song/url?" + new Date(), {
        //获取歌曲
        params: {
          id: _this.soterid[row.playcond],
        },
      })
      .then((res) => {
        // console.log(res.data.data[0].url);
        _this.$store.commit("uptabmusicp", res.data.data[0].url);
      });
  },
  //这个是musiclist中create运行调用获取音乐列表
  musiclist(_this){
    let id = _this.soterid.join(",");
    _this.$axios
      .get("song/url?" + new Date(), {
        //获取歌曲
        params: {
          id: id,
        },
      })
      .then((res) => {
        // res.data.data 获取的是歌曲 里面有url
        console.log(res.data.data);
        _this.$store.commit("upmapurl", res.data.data);
      }).then(()=>{
        _this.off=false
      });
  },
  //loc卡片组件中create调用获取未登入状态歌单
  lcolist(_this){
    _this.$axios
    .get("/personalized", {
      params: {
        limit:30
      },
    })
    .then((res) => {
      // console.log(res.data.result);
      // 限制条数
      let lco = res.data.result.slice(0, 10);
      console.log(lco);
      // let lco=res.data.result
      _this.hot = lco;
      _this.$store.commit("uplcodata", lco);
    });
  },
  //评论借口comment
  comment(_this){
    _this.$axios
    .get("comment/playlist", {
      params: {
        id: _this.$route.query.id,
      },
    })
    .then((res) => {
      _this.total = res.data.total;
      _this.commentdata = res.data.comments;
      _this.$store.commit("uptotal", res.data.total);
      _this.$store.commit("upcommmetn", res.data.comments);
    })
    .catch((err) => {
      console.log(err);
    })
  },
  //评论借口
  collector(_this){
    _this.$axios
    .get("playlist/subscribers", {
      params: {
        id: _this.$route.query.id,
      },
    })
    .then((res) => {
      _this.collectordata = res.data.subscribers;
      // console.log(res.data.subscribers);
    });
  },//
  tabmusict2(_this, index) {
    _this.$axios
      .get("song/url?" + new Date(), {
        //获取歌曲
        params: {
          id: _this.soterid[index],
        },
      })
      .then((res) => {
        // console.log(res.data.data[0].url);
        _this.$store.commit("tabplay", index);
        _this.$store.commit("uptabmusicp", res.data.data[0].url);
      });
  }



}